package com.vrv.vap.baseline.controller;

import com.vrv.vap.baseline.service.impl.MyTicketExportService;
import com.vrv.vap.baseline.util.FileOperationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/api/myticket")
public class MyTicketController {
    @Autowired
    private MyTicketExportService myTicketExportService;
    @Autowired
    private FileOperationUtil fileOperationUtil;

    @GetMapping("/export")
    public void exportZip(HttpServletResponse response) throws IOException {
        String zipFilePath = myTicketExportService.exportZip();
        response.setContentType("application/zip");
        response.setHeader("Content-Disposition", "attachment;filename=myticket.zip");
        try {
            fileOperationUtil.writeFileToResponse(zipFilePath, response);
        } catch (IOException e) {
            throw new RuntimeException("Failed to download zip file", e);
        }
    }
}